/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.karol.lx.model;

import java.io.Serializable;
import java.lang.reflect.Field;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author karol
 */
public class GradeRequest implements Serializable {

    public int id;
    public int action;
    public int status;
    public int mode;
    public Date m_DispatchTime;

    public GradeRequest() {
    }

    public static ArrayList<GradeRequest> buildFromResultSet(ResultSet pSet) {
        ArrayList<GradeRequest> retval = new ArrayList<>();
        try {
            while (pSet.next()) {
                GradeRequest tRequest = new GradeRequest();

                for (Field f : GradeRequest.class.getDeclaredFields()) {
                    if (!f.getName().startsWith("m_")) {
                        try {
                            f.set(tRequest, pSet.getInt(f.getName()));
                        } catch (IllegalArgumentException ex) {
                            Logger.getLogger(GradeRequest.class.getName()).log(Level.SEVERE, null, ex);
                        } catch (IllegalAccessException ex) {
                            Logger.getLogger(GradeRequest.class.getName()).log(Level.SEVERE, null, ex);
                        }
                    }
                }

                retval.add(tRequest);
            }
        } catch (SQLException ex) {
            Logger.getLogger(GradeRequest.class.getName()).log(Level.SEVERE, null, ex);
        }

        return retval;
    }

    @Override
    public String toString() {
        return id + ";" + action + ";" + mode + ";" + status;
    }
}
